#ifndef __LINUX_LIST_H__
#define __LINUX_LIST_H__

struct list_head
{
	struct list_head *next, *prev;
};

#define offsetof(type, member) ((unsigned long)&((type *)0)->member)

#define container_of(ptr, type, member) \
		(type *)((char *)(ptr) - offsetof(type, member))

#define list_entry(list_ptr, struct_type, member_name)\
        container_of(list_ptr, struct_type, member_name)

#define list_last_entry(ptr, type, member) \
	list_entry((ptr)->prev, type, member)

#define list_first_entry(ptr, type, member) \
	list_entry((ptr)->next, type, member)

#define list_for_each(pos, head)\
	for (pos = (head)->next; pos != (head); pos = pos->next)

#define list_for_each_safe(pos, n, head) \
	for (pos = (head)->next, n = pos->next; pos != (head); \
		pos = n, n = pos->next)

#define list_next_entry(pos, member) \
	list_entry((pos)->member.next, typeof(*(pos)), member)

#define list_for_each_entry_safe(pos, n, head, member)       \
	for (pos = list_first_entry(head, typeof(*pos), member), \
		n = list_next_entry(pos, member);                    \
		 &pos->member != (head);                             \
		 pos = n, n = list_next_entry(n, member))

#define list_for_each_entry(pos, head, member)				\
	for (pos = list_first_entry(head, typeof(*pos), member);	\
	     &pos->member != (head);					\
	     pos = list_next_entry(pos, member))

#define list_first_entry_or_null(ptr, type, member) \
	(!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)

void INIT_LIST_HEAD(struct list_head *list);
void __list_add(struct list_head *new_lst, struct list_head *prev, struct list_head *next);
void list_add(struct list_head *new_lst, struct list_head *head);
void list_add_tail(struct list_head *new_lst, struct list_head *head);
void __list_del(struct list_head * prev, struct list_head * next);
void list_del(struct list_head * entry);
void list_remove_chain(struct list_head *ch,struct list_head *ct);
void list_add_chain(struct list_head *ch,struct list_head *ct,struct list_head *head);
void list_add_chain_tail(struct list_head *ch,struct list_head *ct,struct list_head *head);
int list_empty(struct list_head *head);


#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \
	struct list_head name = LIST_HEAD_INIT(name)

#endif

